﻿using System;
using System.Collections;
using System.Linq;
using System;
namespace HomeWork5
{
    class Program
    {
        //func函数实现对输入的动态数组中的数遍历并生成哥德巴赫猜想的结果
        static void func(ArrayList input)
        {
            foreach (int i in input)
            {
                //Console.Write(i+"\n");
            }
            //Console.Write("lalala");
            foreach (int i in input)
            {
                int x;
                for(x=2; x < i; x++)
                {
                    int y = i - x;
                    bool x_issushu=true;
                    bool y_issushu=true;
                    int a, b;
                    for(a = 2; a < x; a++)
                    {
                        if(x%a == 0)
                        {
                            x_issushu = false;
                            
                        }

                    }
                    for (b = 2; b < y; b++)
                    {
                        if (y % b == 0)
                        {
                            y_issushu = false;
                           
                        }
                    }
                    if (x_issushu && y_issushu && (y<=x))
                    {
                        Console.Write(i + "=" + x + "+" + y + "\n");
                        break;
                    }


                }
            }
        }
        
        static void Main(string[] args)
        {
            //第一题：哥德巴赫猜想
            ArrayList al = new ArrayList();
            for(int x = 6; x<=100; x++)
            {
                if(x%2 == 0)
                {
                    //Console.WriteLine(x);
                    al.Add(x);
                }
            }
            func(al);

            


           //第二题
            ArrayList bl = new ArrayList();

            for (int j = 0; j < 100; j++)
            {
                Random rd = new Random();  
                int r = rd.Next(0, 1000);
                //Console.WriteLine(r+"\n");
                bl.Add(r);
            }

            var ran1 = from w in bl.OfType<int>() orderby w descending  select w;
            Console.WriteLine("从大到小排序：");
            foreach (int i in ran1)
            {
                Console.WriteLine(i);
            }
            Console.WriteLine("平均数："+ ran1.Average());
            Console.WriteLine("求和：" + ran1.Sum());

        }
    }
}
